package com.gs.wzmanager.controller;

import com.gs.wzmanager.entity.Channel;
import com.gs.wzmanager.service.ChannelService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "/channel")
public class ChannelController {
    private Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    ChannelService channelService;

    @RequestMapping(value = "/listView")
    public String view(){
        return "channel/list";
    }

    @RequestMapping(value = "queryAll")
    @ResponseBody
    public List<Channel> queryAllChannel() {
        return channelService.queryAllChannel();
    }

    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public ResponseEntity updateChannel(@RequestBody Channel channel) {
        return channelService.update(channel);
    }

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResponseEntity addChannel(@RequestBody Channel channel) {
        logger.info("addChannel->{}", channel);
        return channelService.addChannel(channel);
    }
}
